/**********************************************************************
* 文件名：MqModel.h
* 创建日期：2021-06-16 13:23
* 作者：李志勇
* 邮箱：18771909050@163.com
* 版权声明：Copyright (c) 2021 zhiyongli Technology (China) Limited.
* All rights reserved.
* 修改记录:
***********************************************************************/
#ifndef MQCONTROLLER_H
#define MQCONTROLLER_H

#include <memory>
#include <QObject>

#include "MqModel.h"

class QAmqpClient;
class QAmqpExchange;
class QAmqpQueue;

class MqController : public QObject
{
    Q_OBJECT

public:
    MqController();
    ~MqController();

    void CreateConnect();
    void DisConnect();

    void CreateExchange();
    void CreateQueue();

    /**
     * @brief sendMeg 发送消息
     * @param msg
     */
    void sendMsg(const QString& msg);
    void sendMsg(const QString& msg, const QStringList &routingKey);

    void set_host_name(const QString& host_name);
    QString get_host_name() const;

    void set_port(quint16 port);
    quint16 get_port() const;

    void set_virtual_host(const QString& virtual_host);
    QString get_virtual_host() const;

    void set_user_name(const QString& user_name);
    QString get_user_name() const;

    void set_password(const QString& password);
    QString get_password() const;

    void set_exchange_name(const QString& exchange_name);
    QString get_exchange_name() const;

    void set_exchange_type(QAmqpExchange::ExchangeType type);
    QAmqpExchange::ExchangeType get_exchange_type() const;

    void set_exchange_durable(bool is_durable);
    bool get_exchange_durable() const;

    void set_exchange_autoDelete(bool is_autoDelete);
    bool get_exchange_autoDelete() const;

    void set_queue_name(const QString& queue_name);
    QString get_queue_name() const;

    void set_queue_durable(bool is_durable);
    bool get_queue_durable() const;

    void set_queue_exclusive(bool is_exclusive);
    bool get_queue_exclusive() const;

    void set_queue_autoDelete(bool is_autoDelete);
    bool get_queue_autoDelete() const;

signals:
    /**
     * @brief signal_connect 状态信息
     * @param state_msg 状态信息字符串
     */
    void signal_connect(bool is_connect, const QString& state_msg);
    /**
     * @brief signal_exchangeDeclared 创建交换
     * @param is_declared 交换创建是否成功
     * @param state_msg
     */
    void signal_exchangeDeclared(bool is_declared, const QString& state_msg);
    /**
     * @brief signal_queueDeclared 创建队列
     * @param is_declared 队列创建是否成功
     * @param state_msg
     */
    void signal_queueDeclared(bool is_declared, const QString& state_msg);

    void signal_message_received(const QString& msg);

private slots:
    void slot_connect();
    void slot_disconnect();
    void slot_exchangeDeclared();
    void slot_queueDeclared();

    void slot_message_received();

    void QueueBind();
private:
    std::shared_ptr<QAmqpClient>  m_client{nullptr};
    QAmqpExchange* m_exchange{nullptr};
    QAmqpQueue* m_queue{nullptr};

    MqModel m_mqmodel;

    QString m_save_name{"mqInfo.ini"};
};

#endif // MQCONTROLLER_H
